//和用户相关的共享状态

import { getCurrentUser } from "@/services/userService";
import { showToast } from "vant";

let currentLoginUserState = null;

const getCurrentLoginUserState = async () => {
  if (currentLoginUserState) return currentLoginUserState;
  const { message, description, data: user } = await getCurrentUser();
  if (user) {
    setCurrentLoginUserState(user);
    return user;
  }
  showToast(description.length ? description : message);
};
const setCurrentLoginUserState = (user) => {
  currentLoginUserState = user;
};

export { getCurrentLoginUserState, setCurrentLoginUserState };
